package carconstructioncompany;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class CandidateCode {
	private static Set<String> visited, parent;
	private static Map<String, List<String>> E;
	private static boolean hasCycle(String v) {
		visited.add(v);
		parent.add(v);
		List<String> W = E.get(v);
		if(W != null) {
			for(String w : W) {
				if(parent.contains(w) || !visited.contains(w) && hasCycle(w))
					return true;
			}
		}
		parent.remove(v);
		return false;
	}
    public static String construction(String[] input1) {
    	Set<String> V = new HashSet<String>();
    	E = new HashMap<String, List<String>>();
    	for(String e : input1) {
    		String[] t = e.split("#");
    		V.add(t[0]);
    		V.add(t[1]);
    		List<String> v = E.get(t[0]);
    		if(v == null) {
    			v = new ArrayList<String>();
    			E.put(t[0], v);
    		}
			v.add(t[1]);
    	}
    	visited = new HashSet<String>();
    	for(String v : V) {
    		if(!visited.contains(v)) {
    			parent = new HashSet<String>();
    			if(hasCycle(v))
    				return "No";
    		}
    	}
    	return "Yes";
    }
	public static void main(String[] args) {
		String[] input1 = {"a#b", "b#c", "c#d"};
		System.out.println(construction(input1));
		String[] input2 = {"a#b", "b#c", "c#a"};
		System.out.println(construction(input2));
		String[] input3 = {"a#b", "b#c", "c#d", "b#d"};
		System.out.println(construction(input3));
		String[] input4 = {"a#b", "b#c", "c#d", "d#b"};
		System.out.println(construction(input4));
		String[] input5 = {"a#b", "b#c", "d#b", "b#e"};
		System.out.println(construction(input5));
		String[] input6 = {"a#b", "b#c", "d#b", "b#e", "c#e"};
		System.out.println(construction(input6));
		String[] input7 = {"a#b", "b#c", "d#b", "e#b", "c#e"};
		System.out.println(construction(input7));
	}
}
